﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using TraCuuDiemNhom3.Commons;

namespace TraCuuDiemNhom3
{
    public partial class CapNhatNguoiDung : System.Web.UI.Page
    {
        DataTable tblDiem,tblND, tblMonHoc;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //tblND = TienIchSQL.ChayLenhSelectDuLieu("select  * from NguoiDung");
            //if (!IsPostBack)
            //{

                tblND = TienIchSQL.ChayLenhSelectDuLieu("select  * from NguoiDung");
                gvNguoiDung.DataSource = tblND;
                gvNguoiDung.DataBind();

           // }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < gvNguoiDung.Rows.Count; i++)
            {
                GridViewRow row = gvNguoiDung.Rows[i];
                if (row.RowType != DataControlRowType.DataRow)
                    continue;

                object pw, ht, gt, ns, cv, qu;

                string us = ((HiddenField)row.FindControl("hidenUserName")).Value;

                TextBox txtpw = (TextBox)row.FindControl("txtpw");
                if (string.IsNullOrEmpty(txtpw.Text))
                    pw = "";
                else
                    pw = txtpw.Text;

                TextBox txtht = (TextBox)row.FindControl("txtht");
                if (string.IsNullOrEmpty(txtht.Text))
                    ht = "";
                else
                    ht = txtht.Text;

                TextBox txtgt = (TextBox)row.FindControl("txtgt");
                if (string.IsNullOrEmpty(txtgt.Text))
                    gt = "";
                else
                    gt = txtgt.Text;

                TextBox txtns = (TextBox)row.FindControl("txtns");
                if (string.IsNullOrEmpty(txtns.Text))
                    ns = "";
                else
                    ns = txtns.Text;

                TextBox txtcv = (TextBox)row.FindControl("txtcv");
                if (string.IsNullOrEmpty(txtcv.Text))
                    cv = "";
                else
                    cv = txtcv.Text;

                TextBox txtqu = (TextBox)row.FindControl("txtqu");
                if (string.IsNullOrEmpty(txtqu.Text))
                    qu = "";
                else
                    qu = txtqu.Text;

              int a=  TienIchSQL.ChayLenhUpdateDuLieu("Update NguoiDung set [PassWord]=@p , HoTen=@h,GioiTinh=@g ,NgaySinh=@n ,ChucVu= @c , Quyen= @q where  UserName=@u", "@p", pw, "@h", ht, "@g", gt, "@n", ns, "@c", cv, "@q", qu, "@u", us);

            }
           }

        

        protected void btnView_Click(object sender, EventArgs e)
        {
            //tblDiem = TienIchSQL.ChayLenhSelectDuLieu("Select*, n.HoTen From Diem d, NguoiDung n  where d.MaSV=n.UserName and SubString(n.UserName,5,2) = @maLop and d.HocKy= @hocKy and d.MaMH=@maMH", "@maLop",  "@hocKy","", "@maMH","");                                            
            //gvNguoiDung.DataSource = tblDiem;
            //gvNguoiDung.DataBind();
            //btnDelete.Visible = true;
        }

        protected void ddlHocKy_SelectedIndexChanged(object sender, EventArgs e)
        {
          
        }

       
        protected void ddlLop_SelectedIndexChanged(object sender, EventArgs e)
        {
          //  ddlHocKy_SelectedIndexChanged(sender, e);
            //tblMonHoc = TienIchSQL.ChayLenhSelectDuLieu("Select  distinct m.MaMH, m.TenMH from MonHoc m, diem d, nguoidung n where m.MaMH=d.MaMH and d.MaSV = n.UserName and SubString(n.UserName,5,2)=@maLop and d.HocKy=@hocKy", "@maLop", ddlLop.SelectedValue, "@hocKy", ddlHocKy.Text);
            //ddlMonHoc.DataSource = tblMonHoc;
            //ddlMonHoc.DataTextField = "TenMH";
            //ddlMonHoc.DataValueField = "MaMH";
            //ddlMonHoc.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }

        protected void ddlMonHoc_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void gvNguoiDung_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        protected void btnDelete_Click_Click(object sender, EventArgs e)
        {

        }



        public string tienichweb { get; set; }
    }
}